<?php
function echoLeaguesAndResults($seasons) {
	global $loggedin;
	foreach ($seasons as $currentSeason) {
		echo<<< EOQ
            <br /><br /><a href="league.php?season_id=$currentSeason->id">$currentSeason->shortName</a>
            <br />-&nbsp;<a class="sub" href="results.php?season_id=$currentSeason->id">Results</a>
EOQ;
		if(isset($loggedin)) {
		echo<<< EOQ
            <br />-&nbsp;<a class="sub" href="match_create.php?season_id=$currentSeason->id">Report Result</a>
EOQ;
		}
		if (isCommissioner() || hasFixtures($currentSeason)) {
			echo<<< EOQ
            <br />-&nbsp;<a class="sub" href="fixtures.php?season_id=$currentSeason->id">Fixtures</a>
EOQ;
		}
	}
}

function echoAllSeasonsSelect($seasons) {
	global $defaultSeason, $alternateSeason;
	echo<<< EOQ
            <br /><form method="get">
            <p class="vsmall">Select a season<br /><select name="season_id" style="font-size:7pt;">
EOQ;
	$seasonToSelect = $defaultSeason;
	if ($season->id == $defaultSeason) {
		$seasonToSelect = $alternateSeason;
	}
	foreach ($seasons as $currentSeason) {
		echo "<option value=\"" . $currentSeason->id . "\"";
		if ($currentSeason->id == $seasonToSelect) {
			echo " selected";
		}
		echo ">" . $currentSeason->shortName . "</option>\n";
	}
	echo<<< EOQ
              </select>
              <br /><input type="submit" value="Change season" style="font-size:7pt;"/>
            </form>
EOQ;
}

include_once ("includes/init.php");
include_once ("includes/htmlhead.php");

if (isset ($scriptHead)) {
	echo "\n" . $scriptHead . "\n";
}
echo<<< EOQ
  <body text="$textColor" bgcolor="$bgcolor">
EOQ;
if (isset ($scriptBody)) {
	echo "\n" . $scriptBody . "\n";
}
echo<<< EOQ
    <table cellSpacing="8" cellPadding="0" align="left" border="0">
      <tr>
        <td vAlign="top" align="left" width="125" class="small">
          <A HREF="index.php"><IMG SRC="$rootDir/images/logo.jpg" ALT="League Logo" BORDER="0"></A>
    <br /><br /><a href="index.php">News</a>
	<br /><a href="$forumLink">Forum</a>
    <br /><a href="http://code.google.com/p/doubleskullsleague/wiki/Help" target="doubleSkullsHelp">Help</a>
EOQ;
	echo<<< EOQ
EOQ;
if (!isset ($loggedin)) {
	echo "<br /><a href=\"login.php\">Login</a>\n";
} else {
	echo<<< EOQ
        <br /><a href="coach_details.php?id=$loggedin->id">$loggedin->name Info</a>
		<br /><a href="coach_editor.php">Edit Profile</a>
EOQ;
}
echoLeaguesAndResults($activeSeasons);
	echo<<< EOQ
	<br />
    <br /><a href="rules.php">Rules</a>
    <br /><a href="hof.php">Hall of Fame</a>
	<br /><a href="player_deaths.php">The Fallen</a>
    <br /><a href="stats.php">Statistics</a>
EOQ;
if (isset ($showStats)) {
	echo<<< EOQ
        <br />-&nbsp;<a href="./player_games.php">Player&nbsp;Game</a>
        <br />-&nbsp;<a href="./player_stats.php">Player&nbsp;Overall</a>
        <br />-&nbsp;<a href="./sequences.php">Sequences</a>
        <br />-&nbsp;<a href="./armour.php">Team&nbsp;Cas</a>
        <br />-&nbsp;<a href="./team_averages.php">Team&nbsp;Ave</a>
        <br />-&nbsp;<a href="./team_spps.php">Team&nbsp;SPPs</a>
EOQ;
}
$updateRs = executeQuery("select date_format(update_timestamp, '%b %e %k:%i') from updates");
$updateRow = mysql_fetch_row($updateRs);
if (isset ($additionalLinks)) {
	foreach (array_keys($additionalLinks) as $key) {
		$value = $additionalLinks[$key];
		echo<<< EOQ
            <br /><a href="$value">$key</a>
EOQ;
	}
}
echo<<< EOQ
            <br /><a href="team_creator.php">Team&nbsp;Creator</a>
EOQ;
if (isset ($showRaceLinks)) {
	echoRaceLinks($races);
}
if (isCommissioner()) {
	echo<<< EOQ
        <br /><br /><strong class="small">Administration</strong>
        <br />-&nbsp;<a class="sub" href="news_editor.php">News Editor</a>
        <br />-&nbsp;<a class="sub" href="seasons.php">Seasons</a>
        <br />-&nbsp;<a class="sub" href="season_editor.php">Conferences</a>
        <br />-&nbsp;<a class="sub" href="adjustments.php">Point Adjustment</a>
        <br />-&nbsp;<a class="sub" href="admin.php">Admin Functions</a>
EOQ;
}
echo<<< EOQ
            <br /><br /><strong class="small">Probabilties</strong>
            <br />-&nbsp;<a class="sub" href="gfi.php">Going For It</a>
            <br />-&nbsp;<a class="sub" href="blocking.php">Blocking</a>
            <br />-&nbsp;<a class="sub" href="injury.php">Injuries</a>
            <br /><br /><a href="contact_us.php">Contact Us</a>
		    <br /><a href="?reload=true">Refresh</a>
            <br /><a href="http://code.google.com/p/doubleskullsleague/" title="This website is an open source project on google code">Open Source</a> 
            <br /><p class="small">Last Change<br />$updateRow[0]
EOQ;
if (!isset ($noSeasonChange)) {
	echoAllSeasonsSelect($seasons);
}
echo<<< EOQ
          </p>
        </td>
        <td vAlign="top" width="*%">
          <table border="0" cellPadding="5" cellSpacing="0" width="100%">
EOQ;
?>
